<?php
include "../../../lib/list.php";
if($_POST['mode']=='insert'){
	$no=$_POST['no'];
	$name=$_POST['name'];
	$note=$_POST['note'];

	for($i=0;$i<count($no);$i++){
	if(!$name[$i]){
		echo("
	    <script>
	      window.alert('그룹명을 입력해주세요.');
	      window.alert('내용 입력에 실패했습니다.');
		  location.href='view.php';
	      </script>");
		return;
	}
	else{
		if(!$no[$i]){
			$no[$i] = 'NULL';
		}
		
		$query = sprintf("INSERT INTO uatp_shopgroup(no,name,note) VALUES(%d,'%s','%s')
				ON DUPLICATE KEY UPDATE name='%s', note='%s'",
		$no[$i],
		clean($name[$i]),
		clean($note[$i]),
		clean($name[$i]),
		clean($note[$i]));
		DBquery($query);
	}
	}
	mysql_close();
	echo "<script>
				window.alert('그룹을 입력했습니다.');
				location.href='view.php';
		  </script>";
}
if($_POST['mode']=='delete'){
	$no=$_POST['chk_no'];
	for($i=0;$i<count($no);$i++){
		$query = sprintf("DELETE FROM `uatp_shopgroup` WHERE `no` = %d",$no[$i]);
		DBquery($query);
	}
	mysql_close();
	echo "<script>
					window.alert('폐점하였습니다.');
					location.href='view.php';
			  </script>";
}